const { chromium } = require('playwright');
const path = require('path'); // 修复：添加 path 模块引入

(async () => {
  const pathToExtension = 'C:\\Users\\明达\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\nkbihfbeogaeaoehlefnkodbefgpgknn\\12.18.2_0';
  const userDataDir = path.join(__dirname, '/tmp/test-user-data-dir');
  const browserContext = await chromium.launchPersistentContext(userDataDir, {
    channel: 'chromium',
    headless: false, // 新增：显式禁用无头模式，启用图形界面
    // executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`
    ]
  });
  const page = await browserContext.newPage();
  await page.goto('https://www.baidu.com')
//   await browserContext.close();
})();